package game.zqll.systems;

import com.artemis.Aspect;
import com.artemis.systems.IteratingSystem;
import com.badlogic.gdx.math.MathUtils;
import game.zqll.ModSampleApplication;
import game.zqll.components.BucketComp;
import game.zqll.components.MoveComp;
import game.zqll.components.PosComp;

public class RecycleEntitySystem extends IteratingSystem {

    public RecycleEntitySystem() {
        super(Aspect.all(PosComp.class, MoveComp.class));
    }

    @Override
    protected void process(int entityId) {
        PosComp posComp = Mappers.pos.get(entityId);
        if (posComp.x < 0 || posComp.x > ModSampleApplication.worldWidth - 32f ||
            posComp.y < 0 || posComp.y > ModSampleApplication.worldHeight) {
            if (world.getEntity(entityId).getComponent(BucketComp.class) != null) {
                posComp.x = MathUtils.clamp(posComp.x, 0, ModSampleApplication.worldWidth - 32f);
                posComp.y = MathUtils.clamp(posComp.y, 0, ModSampleApplication.worldHeight);
                return;
            }
            world.delete(entityId);
        }
    }
}
